package com.shenfa.dao.work;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.SqlMapClientTemplate;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.shenfa.bean.CheckRuleData;
import com.shenfa.bean.Template;
import com.shenfa.bean.work.BillEList;
import com.shenfa.bean.work.BillPList;
import com.shenfa.bean.work.Check;
import com.shenfa.bean.work.ComposeLog;
import com.shenfa.bean.work.Watch;
import com.shenfa.bean.work.WatchState;
import com.shenfa.bean.work.XmlLog;
import com.shenfa.bean.xml.PointInfo;
import com.shenfa.bean.xml.UserBase;

public class XmlLogDao {

	@Autowired
	private SqlMapClientTemplate sqlMapClientTemplate;

	@Autowired
	private SqlMapClient sqlMapClient;

	/**
	 * 根据条件查询 XML生成日志
	 * 
	 * @param xmllog
	 * @param skipResults
	 * @param maxResults
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<XmlLog> xmlLogGridList(XmlLog xmllog, int skipResults,
			int maxResults) {
		List<XmlLog> list = new ArrayList<XmlLog>();
		list = sqlMapClientTemplate.queryForList("logxml_manager.query_xmllog",
				xmllog, skipResults, maxResults);
		return list;
	}

	/**
	 * 查询总XmlLog条数
	 * 
	 * @param xmllog
	 * @return
	 */
	public Object totalListlen(XmlLog xmllog) {
		return sqlMapClientTemplate.queryForObject(
				"logxml_manager.query_total", xmllog);
	}

	/**
	 * 查询总ComposeLog条数
	 * 
	 * @param Comlog
	 * @return
	 */
	public Object totalComListlen(ComposeLog Comlog) {
		return sqlMapClientTemplate.queryForObject(
				"logxml_manager.query_comptotal", Comlog);
	}

	/**
	 * 根据条件查询 电子/纸质合成日志
	 * 
	 * @param Comlog
	 * @param skipResults
	 * @param maxResults
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<ComposeLog> composeLogGridList(ComposeLog Comlog,
			int skipResults, int maxResults) {
		List<ComposeLog> list = new ArrayList<ComposeLog>();
		try {
			list = sqlMapClient.queryForList("logxml_manager.query_composelog",
					Comlog, skipResults, maxResults);
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}
		return list;
	}

	/**
	 * 查询抽样所需的电子/纸质合成日志
	 * 
	 * @param Comlog
	 * @param skipResults
	 * @param maxResults
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<ComposeLog> sampleComposeLogGrid(ComposeLog Comlog,
			int skipResults, int maxResults) {
		List<ComposeLog> list = new ArrayList<ComposeLog>();
		try {
			list = sqlMapClient.queryForList(
					"logxml_manager.query_composelogAll", Comlog, skipResults,
					maxResults);
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}
		return list;
	}

	/**
	 * 查询合成监控状态表
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<WatchState> watchStateGridList(WatchState watchState,
			int start, int limit) {
		List<WatchState> list = new ArrayList<WatchState>();
		list = sqlMapClientTemplate.queryForList("logxml_manager.query_watch",
				watchState, start, limit);
		return list;
	}

	/**
	 * 查询合成监控状态表总条数
	 * 
	 * @return
	 */
	public Object totalWatchlen(WatchState watchState) {
		return sqlMapClientTemplate.queryForObject(
				"logxml_manager.query_watchtotal", watchState);
	}

	/**
	 * 修改账单状态
	 * 
	 * @return
	 */
	public int updComposeLogState(ComposeLog Comlog) {
		try {
			sqlMapClient.update("logxml_manager.update_state", Comlog);
		} catch (SQLException e) {
			e.printStackTrace();
			return 0;
		}
		return 1;
	}

	/**
	 * 查询纸质账单明细表
	 * 
	 * @param birth
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<BillPList> checkBillp(BillPList bp, int start, int limit) {
		List<BillPList> list = new ArrayList<BillPList>();
		try {
			list = sqlMapClient.queryForList("logxml_manager.checkbillp", bp,
					start, limit);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}

	/**
	 * 
	 * @param bp
	 * @return
	 */
	public Object totalCheckBillp(BillPList bp) {
		return sqlMapClientTemplate.queryForObject(
				"logxml_manager.checkbillpCount", bp);
	}

	/**
	 * 查询电子账单明细
	 */
	@SuppressWarnings("unchecked")
	public List<BillEList> checkBille(BillEList b_e, int start, int limit) {
		List<BillEList> list = new ArrayList<BillEList>();
		try {
			list = sqlMapClient.queryForList("logxml_manager.checkbille", b_e,
					start, limit);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}

	/**
	 * 
	 * @param b_e
	 * @return
	 */
	public Object totalCheckBille(BillEList b_e) {
		return sqlMapClientTemplate.queryForObject(
				"logxml_manager.checkbilleCount", b_e);
	}

	/**
	 * watch查询
	 * 
	 * @author longchensan create by 2011-10-11
	 * @param start
	 * @param limit
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<Watch> queryWatch(int start, int limit) {
		List<Watch> list = null;
		try {
			list = sqlMapClient.queryForList("logxml_manager.queryWatch",
					start, limit);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}

	/**
	 * 分页总条数
	 * 
	 * @return
	 */
	public Object totalWatch() {
		int a = 0;
		try {
			a = (Integer) sqlMapClient
					.queryForObject("logxml_manager.queryWatchCount");
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return a;
	}

	/**
	 * 查询模板有误的产品
	 * 
	 * @param start
	 * @param limit
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<Template> queryAllProd(int start, int limit) {
		List<Template> temp = new ArrayList<Template>();
		try {
			temp = sqlMapClient.queryForList("logxml_manager.queryAllProd",
					start, limit);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return temp;
	}

	/**
	 * 所有启用产品对应的启用模板
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<Template> queryCheckData() {
		List<Template> temp = new ArrayList<Template>();
		try {
			temp = sqlMapClient.queryForList("logxml_manager.getCheckData");
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return temp;
	}

	/**
	 * 数据验证——模板验证分页总条数
	 * 
	 * @return
	 */
	public Object totalCDTemp() {
		int a = 0;
		try {
			a = (Integer) sqlMapClient
					.queryForObject("logxml_manager.getCDTempPage");
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return a;
	}

	/**
	 * 数据验证——规则验证,所有有效模板对应的区域
	 * 
	 * @param start
	 * @param limit
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<CheckRuleData> queryArea(int start, int limit) {
		List<CheckRuleData> rule = new ArrayList<CheckRuleData>();
		try {
			rule = sqlMapClient.queryForList("logxml_manager.getAllRule",
					start, limit);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return rule;
	}

	/**
	 * 数据验证——规则验证,所有有效模板对应的区域分页总条数
	 * 
	 * @return
	 */
	public int queryRuleTotalPage() {
		int rule = 0;
		try {
			rule = (Integer) sqlMapClient
					.queryForObject("logxml_manager.getRuleTotalPage");
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return rule;
	}

	/**
	 * 设置了默认规则的模板区域
	 * 
	 * @param temp
	 * @return
	 */
	public int queryDefRule(CheckRuleData temp) {
		int rule = 0;
		try {
			rule = (Integer) sqlMapClient.queryForObject(
					"logxml_manager.getDefRule", temp);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return rule;
	}

	/**
	 * 设置了默认正确规则的模板区域
	 * 
	 * @param temp
	 * @return
	 */
	public int queryRightDefRule(CheckRuleData temp) {
		int rule = 0;
		try {
			rule = (Integer) sqlMapClient.queryForObject(
					"logxml_manager.getRight", temp);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return rule;
	}

	/**
	 * V+,积分,AllReady查询
	 * 
	 * @param chek
	 * @param start
	 * @param limit
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<Check> queryVJACheck(Check chek, int start, int limit) {
		List<Check> rule = new ArrayList<Check>();
		try {
			rule = sqlMapClient.queryForList("logxml_manager.queryCheck", chek,
					start, limit);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return rule;
	}
	
	/**
	 * V+,积分,AllReady查询总条数
	 * 
	 * @param temp
	 * @return
	 */
	public int queryCheckPage(Check chek) {
		int rule = 0;
		try {
			rule = (Integer) sqlMapClient.queryForObject(
					"logxml_manager.queryCheckPage", chek);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return rule;
	}
	
	/**
	 * 全部通过
	 * 
	 * @return
	 */
	public int updateCheck(String period){
		int a = 0;
		try {
			a = sqlMapClient.update("logxml_manager.updateCheck",period);
		} catch (SQLException e) {
			e.printStackTrace();
			return a;
		}
		return a;
	}
	
	/**
	 * 查询账单城市设置为空项
	 * 
	 * @param start
	 * @param limit
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<UserBase> queryCity(String period,int start,int limit){
		List<UserBase> list= new ArrayList<UserBase>();
		try {
			list = sqlMapClient.queryForList("logxml_manager.queryCity", period, start, limit);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}
	
	/**
	 * 总条数
	 * 
	 * @return
	 */
	public int queryCityPage(String period) {
		int rule = 0;
		try {
			rule = (Integer) sqlMapClient.queryForObject("logxml_manager.queryCityPage",period);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return rule;
	}
	
	/**
	 * 设置账单城市为其他城市
	 * 
	 * @return
	 */
	public int updateCity(String period){
		int a = 0;
		try {
			a = sqlMapClient.update("logxml_manager.updateCity",period);
		} catch (SQLException e) {
			e.printStackTrace();
			return a;
		}
		return a;
	}
	
	/**
	 * 积分验证,分页查询
	 * 
	 * @param period 账单日
	 * @param start
	 * @param limit
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<PointInfo> queryJFCheck(String period,int start,int limit){
		List<PointInfo> list= new ArrayList<PointInfo>();
		try {
			list = sqlMapClient.queryForList("makexml.quycheckJF", period, start, limit);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}
	
	/**
	 * 积分验证分页总条数
	 * 
	 * @param period
	 * @return
	 */
	public int queryJFCheckPage(String period){
		int a = 0;
		try {
			a = (Integer)sqlMapClient.queryForObject("makexml.quycheckJFPage",period);
		} catch (SQLException e) {
			e.printStackTrace();
			return a;
		}
		return a;
	}
	
	/**
	 * 将验证有误的积分插入到check_point表中
	 * 
	 * @param period
	 * @return
	 */
	public int addJFCheck(String period){
		int a = 0;
		try {
			Object obj = sqlMapClient.insert("makexml.intcheckJF", period);
			if(null!=obj){
				a = (Integer)obj;
			}
		} catch (SQLException e) {
			e.printStackTrace();
			return a;
		}
		return a;
	}
	
	/**
	 * 删除原表有误积分
	 * 
	 * @param period
	 * @return
	 */
	public int delJFCheck(String period){
		int a = 0;
		try {
			a = (Integer) sqlMapClient.delete("makexml.delcheckJF", period);
		} catch (SQLException e) {
			e.printStackTrace();
			return a;
		}
		return a;
	}
	
	/**
	 * 预印纸验证
	 * 
	 * @param period
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<Check> queryYYZ(String period){
		List<Check> list= new ArrayList<Check>();
		try {
			list= sqlMapClient.queryForList("logxml_manager.queryYYZ",period);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}
}
